//
//  BaseVC.m
//  SHNet
//
//  Created by FranklinPhill on 15/12/17.
//  Copyright © 2015年 Fire. All rights reserved.
//

#import "BaseVC.h"
#import "BottomBarView.h"

@interface BaseVC () <UITabBarDelegate>

@end

@implementation BaseVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = YES;
    self.view.backgroundColor = [UIColor whiteColor];
//    [self initTopBarView];
    [self initBottomBar];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 标题栏

- (void)initTopBarView {
    self.topBarView = [[[NSBundle mainBundle] loadNibNamed:@"TopBarView" owner:nil options:nil] firstObject];
    _topBarView.frame = CGRectMake(0.f, 0.f, kViewWidth, kTitleBarHeight);
    _topBarView.tag = 100;
    
    UIButton *leftBtn = (UIButton *)[_topBarView viewWithTag:1001];
    [leftBtn addTarget:self action:@selector(btnLeftClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    UIButton *rightBtn = (UIButton *)[_topBarView viewWithTag:1003];
    [rightBtn addTarget:self action:@selector(btnRightClicked:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:_topBarView];
}

- (void)setBarTitle:(NSString*)title {
    UIView *barView = [self.view viewWithTag:100];
    UILabel *label = (UILabel*)[barView viewWithTag:1002];
    [label setText:title];
}

- (void)setLeftBtnFrame:(CGRect)rect {
    UIView *barView = [self.view viewWithTag:100];
    UIButton *leftBtn = (UIButton*)[barView viewWithTag:1001];
    [leftBtn setFrame:rect];
}

- (void)setLeftBtnHidden:(BOOL)hidden {
    UIView *barView = [self.view viewWithTag:100];
    UIButton *leftBtn = (UIButton*)[barView viewWithTag:1001];
    [leftBtn setHidden:hidden];
}

- (void)setLeftButtonWithTitle:(NSString *)title normalImg:(UIImage *)normalImg highLightedImg:(UIImage *)highLightedImg {
    UIView *barView = [self.view viewWithTag:100];
    UIButton *leftBtn = (UIButton*)[barView viewWithTag:1001];
    if (title) {
        [leftBtn setTitle:title forState:UIControlStateNormal];
    }
    if (normalImg) {
        [leftBtn setImage:normalImg forState:UIControlStateNormal];
    }
    if (highLightedImg) {
        [leftBtn setImage:highLightedImg forState:UIControlStateHighlighted];
    }
}

- (void)setRightBtnHidden:(BOOL)hidden {
    UIView *barView = [self.view viewWithTag:100];
    UIButton *rightBtn = (UIButton*)[barView viewWithTag:1003];
    [rightBtn setHidden:hidden];
}

- (void)setRightButtonWithTitle:(NSString*)title normalImg:(UIImage *)normalImg highLightedImg:(UIImage *)highLightedImg
{
    UIView *barView = [self.view viewWithTag:100];
    UIButton *rightBtn = (UIButton*)[barView viewWithTag:1003];
    if (title) {
        [rightBtn setTitle:title forState:UIControlStateNormal];
    }
    if (normalImg) {
        [rightBtn setImage:normalImg forState:UIControlStateNormal];
    }
    if (highLightedImg) {
        [rightBtn setImage:highLightedImg forState:UIControlStateHighlighted];
    }
}

- (void)setRightBtnEnabled:(BOOL)enable {
    UIView *barView = [self.view viewWithTag:100];
    UIButton *rightBtn = (UIButton*)[barView viewWithTag:1003];
    [rightBtn setEnabled:enable];
}

//不绑定事件, 由子类自行覆盖
- (void)btnLeftClicked:(id)sender {}

- (void)btnRightClicked:(id)sender {}

#pragma mark - BottomBar

- (void)initBottomBar {
    self.bottomBarView = [[[NSBundle mainBundle] loadNibNamed:@"BottomBarView" owner:nil options:nil] firstObject];
    _bottomBarView.frame = CGRectMake(0.f, kViewHeight - 49, kViewWidth, 49);
    _bottomBarView.tag = 200;
    
    BottomBarView *barView = (BottomBarView *)_bottomBarView;
    barView.tabbar.delegate = self;
    
    [self.view addSubview:_bottomBarView];
}

@end
